const fs = require('fs');
const path = require('path');
const cp = require('./copy');

const spellsDir = path.resolve(__dirname, '../spells'); // 你的spells目录路径
const distDir = path.resolve(__dirname, '../metadata/spells') // 你的输出spells目录路径

const needCopyList = ['cold_comet', 'curses_02', 'grd_zones']

// 判断有没有输出目录, 没有就创建
if (!fs.existsSync(distDir)) {
  fs.mkdirSync(distDir);
}

let aocFileList = []
// 遍历第一级目录
const files = fs.readdirSync(spellsDir)
files.forEach(file => {
  // 判断是不是目录
  if (fs.statSync(path.resolve(spellsDir, file)).isDirectory()) {
    // 拷贝空目录
    if (needCopyList.includes(file)) {
      fs.mkdirSync(path.resolve(distDir, file), { recursive: true })
      aocFileList = [...aocFileList, ...cp.copyDir(path.resolve(spellsDir, file), path.resolve(distDir, file))]
    }
  }
});

aocFileList.forEach(item => {
  cp.copyFile(item)
})


// let item =  {
//   name: 'frostbite_surge_wave.aoc',
//   oldPath: 'E:\\spells\\curses_02\\surges\\frostbite_surge_wave.aoc',
//   newPath: 'E:\\metadata\\spells\\curses_02\\surges\\frostbite_surge_wave.aoc'
// }
// cp.copyFile(item)